package cn.itsource.user.controller;

import cn.itsource.basic.utils.AjaxResult;
import cn.itsource.user.service.impl.CodeServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RestController
@RequestMapping("/code")
public class CodeController {
    @Autowired
    private CodeServiceImpl codeService;
    /*
        1. 接收手机号
        2. 产生一个验证码  4  或者 6 为数字随机数
        3. 给对应的手机发送验证码---》中国网建

        4.验证码存储问题


     */
    @PostMapping("/sendCode")
    public AjaxResult sendCode(@RequestBody HashMap<String, String> map) {
        String phone = map.get("phone");
        try {
            codeService.sendCodeService(phone);
        } catch (Exception e) {
            return new  AjaxResult(e.getMessage());

        }


        return  AjaxResult.me();
    }
}
